<?php
require_once dirname(__FILE__) . '/../../../bootstrap.unit.php';
require_once FORAGE_APP_PATH   . '/features/faceting/FacetingResponseFeature.php';

class FacetingResponseFeatureTest extends ForageUnitTestCase
{
  private $response;

  public function setUp()
  {
    $this->response = new ForageResponse();
    $this->response->addFeature(new ForageFacetingResponseFeature());
  }

  public function tearDown()
  {
    unset($this->response);
  }

  public function addFacets()
  {
    $facet = new ForageFacet('colour');
    $facet->addValue('blue', 3, true);
    $facet->addValue('black', 6);
    $facet->addValue('green', 2);
    $this->response->addFacet($facet);
    $facet = new ForageFacet('shape');
    $facet->addValue('square', 5);
    $facet->addValue('circle', 3);
    $facet->addValue('triangle', 2);
    $this->response->addFacet($facet);
  }

  public function testSettingFacets()
  {
    $this->addFacets();
    $facets = $this->response->getFacets();
    $this->assertEquals(2, count($facets));
    $this->assertEquals('colour', $facets['colour']->field);
    $this->assertEquals('shape',  $facets['shape']->field);
  }

  public function testGettingFacetsWhichAreBeingFilteredOn()
  {
    $this->addFacets();
    $facets = $this->response->getFilterFacets();
    $this->assertEquals(1, count($facets));
    $this->assertEquals('colour', $facets[0]->field);
  }

  public function testGettingFacetsWhichAreNonBeingFilteredOn()
  {
    $this->addFacets();
    $facets = $this->response->getNonFilterFacets();
    $this->assertEquals(1, count($facets));
    $this->assertEquals('shape', $facets[0]->field);
  }
}
